﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using CodeBuilder.DBM;

namespace CodeBuilder.DAO
{
    class DataAccess
    {
        /// <summary>
        /// 根据指定语句更新数据库中的内容
        /// </summary>
        /// <param name="sql">更新语句</param>
        /// <returns>在更新过程中出现的异常</returns>
        public Exception UpdateData(string sql)
        {
            Exception ex = new Exception();
            try
            {
                SqlCommand sqlCommand = new SqlCommand(sql, DBManager.sqlConn);
            }
            catch (Exception e)
            {
                ex = e;
            }
            return ex;
        }
        /// <summary>
        /// 根据指定的 sql 语句得到 DataTable
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <returns>查询到的 dt</returns>
        public DataTable GetDataTable(string sql)
        {
            SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql,DBManager.sqlConn);
            DataTable dt = new DataTable();
            sqlAdapter.Fill(dt);
            return dt;
        }
        /// <summary>
        /// 根据指定的 sql 语句得到 DataSet
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <returns>查询到的 ds</returns>
        public DataSet GetDataSet(string sql)
        {
            SqlDataAdapter sqlAdapter = new SqlDataAdapter(sql, DBManager.sqlConn);
            DataSet ds = new DataSet();
            sqlAdapter.Fill(ds);
            return ds;
        }
        /// <summary>
        /// 按照参数生成符合要求的连接串
        /// </summary>
        /// <param name="dbName">要连接的数据库的名称</param>
        public void CreateConnectionString(string dbName)
        {
            DBManager dbm = new DBManager();
            DBManager.database = dbName;
            //DBManager.BuildSqlConnection();
        }
        /// <summary>
        /// 按照参数生成符合要求的连接串
        /// </summary>
        /// <param name="server">要连接的服务器</param>
        public void SelectServer(string server)
        {
            DBManager dbm = new DBManager();
            DBManager.server = server;
        }
    }
}
